﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Diagnostics;
using System.IO;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Options;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver.Builders;
using MongoDB.Driver.GridFS;
using MongoDB.Driver.Wrappers;


public partial class _Default : System.Web.UI.Page 
{

    protected void Page_Load(object sender, EventArgs e)
    {
        //MongoServer server = MongoServer.Create(); // connect to localhost
        //MongoDatabase db = server.GetDatabase("test");
        //// 获取集合employees
        //MongoCollection collection = db.GetCollection("employees");
        //// -------------------------------------------------------------------------            
        //// 创建一个employee
        //BsonDocument employee = new BsonDocument {{ "name", "Ernest Hemingway" },{ "title", "For Whom the Bell Tolls" }};
        //// 把它写到上面那个集合里面去
        //collection.Insert(employee);

        //// 查询上面那个刚刚插进去的数据，就这格式了，看看QueryDocument的文档吧
        //var query = new QueryDocument("name", "Ernest Hemingway");

        //MongoCollection<BsonDocument> employees = db.GetCollection<BsonDocument>("employees");

        //// 遍历结果
        //foreach (BsonDocument emp in employees.Find(query))
        //{
        //    // BsonValue有两种取值方式，下面两个都用了一个是AsXXX,一个是ToXXX
        //    Label_Test.Text += emp["name"].AsString + emp["title"].ToString();
        //}
        //Label_Test.Text = 

        MongoServer server = MongoServer.Create(); // connect to localhost
        MongoDatabase db = server.GetDatabase("swallow");
        // 获取集合employees
        MongoCollection collection = db.GetCollection("taobao2");
        // -------------------------------------------------------------------------            
        //// 创建一个employee
        //BsonDocument item = new BsonDocument { { "name", "Ernest Hemingway" }, { "title", "For Whom the Bell Tolls" } };
        //// 把它写到上面那个集合里面去
        //collection.Insert(employee);

        // 查询上面那个刚刚插进去的数据，就这格式了，看看QueryDocument的文档吧
        var query = new QueryDocument("price", 258);

        MongoCollection<BsonDocument> items = db.GetCollection<BsonDocument>("taobao2");

        // 遍历结果
        foreach (BsonDocument ite in items.Find(query))
        {
            // BsonValue有两种取值方式，下面两个都用了一个是AsXXX,一个是ToXXX
            Label_Test.Text += ite["name"].AsString + ite["price"].ToString() + " </br>";
        }
    }
}
